@extends('layouts._admin')
@section('title')
    编辑文章
@endsection

@section('css')
    <style>
        .dishes-img{
            display: none;
            margin-top:10px;
        }
    </style>
    @endsection
    @section('content')
            <!-- content -->
    <div class="app-content">
        <div ui-butterbar></div>
        <a href class="off-screen-toggle hide" data-toggle="class:off-screen" data-target=".app-aside"></a>
        <div class="app-content-body fade-in-up">
            <!-- COPY the content from "tpl/" -->
            <div class="hbox hbox-auto-xs hbox-auto-sm">
                <div class="col">
                    <div class="wrapper-md ng-scope" ng-controller="FormDemoCtrl">
                        <div class="panel panel-default">
                            <div class="panel-heading font-bold">
                                编辑文章
                            </div>
                            <div class="panel-body">
                                @include('shared.errors')

                                <form class="form-horizontal" role="form" method="POST" action="{{ route('admin.article.store') }}" enctype="multipart/form-data">
                                    {{ csrf_field() }}

                                    <div class="form-group{{ $errors->has('title') ? ' has-error' : '' }}">
                                        <label for="title" class="col-md-4 control-label">Title</label>

                                        <div class="col-md-6">
                                            <input id="title" type="text" class="form-control" name="title" value="{{ $article->title }}">

                                            @if ($errors->has('title'))
                                                <span class="help-block">
                                                    <strong>{{ $errors->first('title') }}</strong>
                                                </span>
                                            @endif
                                        </div>
                                    </div>

                                    <div class="line line-dashed b-b  pull-in"></div>

                                    <div class="form-group{{ $errors->has('describe') ? ' has-error' : '' }}">
                                        <label for="describe" class="col-md-4 control-label">Describe</label>

                                        <div class="col-md-6">
                                            <input id="describe" type="text" class="form-control" name="describe" value="{{ $article->describe }}">

                                            @if ($errors->has('describe'))
                                                <span class="help-block">
                                                    <strong>{{ $errors->first('describe') }}</strong>
                                                </span>
                                            @endif
                                        </div>
                                    </div>

                                    <div class="line line-dashed b-b  pull-in"></div>

                                    <div class="form-group{{ $errors->has('key_word') ? ' has-error' : '' }}">
                                        <label for="key_word" class="col-md-4 control-label">Key Word</label>

                                        <div class="col-md-6">
                                            <input id="key_word" type="text" class="form-control" name="key_word" value="{{ $article->key_word }}">

                                            @if ($errors->has('key_word'))
                                                <span class="help-block">
                                                    <strong>{{ $errors->first('key_word') }}</strong>
                                                </span>
                                            @endif
                                        </div>
                                    </div>

                                    <div class="line line-dashed b-b  pull-in"></div>

                                    <div class="form-group{{ $errors->has('category_id') ? ' has-error' : '' }}">
                                        <label for="category_id" class="col-md-4 control-label">Category</label>

                                        <div class="col-md-6">

                                            <select class="form-control" name="category_id" id="category_id">
                                                @foreach($category as $cate)
                                                    <option value="{{$cate->cate_id}}">{{$cate->cate_name}}</option>
                                                @endforeach
                                            </select>

                                            @if ($errors->has('category_id'))
                                                <span class="help-block">
                                                    <strong>{{ $errors->first('category_id') }}</strong>
                                                </span>
                                            @endif
                                        </div>
                                    </div>

                                    <div class="line line-dashed b-b  pull-in"></div>

                                    <div class="form-group">
                                        <label for="cover" class="col-md-4 control-label">Cover</label>

                                        <div class="col-md-6">
                                            <input type="file" name="cover" id="cover" value="" class="dishes" ui-jq="filestyle" />
                                            <img width="200" height="200" src="" class="dishes-img" />
                                        </div>
                                    </div>

                                    <div class="line line-dashed b-b  pull-in"></div>

                                    <div class="form-group">
                                        <label for="cover" class="col-md-4 control-label">Content</label>

                                        <div class="col-md-6">
                                            <div id="editor">{{ $article->content }}</div>
                                            <textarea style="display: none;" name="content" id="content" cols="30" rows="10">{{ $article->content }}</textarea>
                                        </div>

                                    </div>

                                    <div class="line line-dashed b-b  pull-in"></div>

                                    <div class="form-group">
                                        <div class="col-md-6 col-md-offset-4">
                                            <button type="submit" class="btn btn-primary result">
                                                保存
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script type="text/javascript" src="{{asset('resources/assets/style/js/style.js')}}"></script>
    <script type="text/javascript" src="{{asset('resources/assets/style/js/wangEditor.min.js')}}"></script>

    <script>



        $(".dishes[type='file']").change(function() {
            $(".dishes-img").show();
        });

        var E = window.wangEditor;
        var editor = new E('#editor');

        editor.customConfig.uploadImgMaxSize = 3 * 1024 * 1024;  //限制文件大小
        editor.customConfig.uploadImgMaxLength = 1; // 限制一次最多上传 1 张图片

        editor.customConfig.uploadImgHeaders = {
            'X-CSRF-TOKEN': '{{ csrf_token() }}'
        };

        editor.customConfig.uploadImgServer = "{{route('upload.server')}}";
        // 或者 var editor = new E( document.getElementById('#editor') )
        editor.create();

        $('.result').click(function() {
            $('#content').text(editor.txt.html());
        });

    </script>
@endsection